package cn.ecpay.unionpay.settle.dao;

import cn.ecpay.unionpay.settle.entity.db.TPvTuiHuiNotify;
import org.rex.DB;
import org.rex.db.exception.DBException;
import org.springframework.stereotype.Repository;

/**
 * 退汇
 * Created by zhaoyanzeng on 2018/12/11.
 */
@Repository
public class TuiHuiDao {
    public void insert(TPvTuiHuiNotify tuiHuiNotify) throws DBException {
        String sql = "INSERT INTO T_PV_TUI_HUI_NOTIFY" +
                "(ID,TXN_TYPE,TXN_NO,ACQ_INS_CODE,TXN_DATE,PAYER_BANK_NO,PAYER_ACCT_NO,PAYER_ACCT_NAME,PAYEE_ACCT_NO,PAYEE_ACCT_NAME," +
                "CURRENCY_CODE,TXN_AMT,PAYEE_ACCT_BAL,ACCT_DATE,ORIG_TXN_NO,ORIG_TXN_DATE,CREATE_TIME,MER_ID,MER_NAME," +
                "REMARK,NOTIFY_VALIDATE) " +
                "VALUES" +
                "(#{id},#{txnType},#{txnNo},#{acqInsCode},#{txnDate},#{payerBankNo},#{payerAcctNo},#{payerAcctName},#{payeeAcctNo}," +
                "#{payeeAcctName},#{currencyCode},#{txnAmt},#{payeeAcctBal},#{acctDate},#{origTxnNo},#{origTxnDate}," +
                "#{createTime},#{merId},#{merName},#{remark},#{notifyValidate})";
        DB.update(sql, tuiHuiNotify);
    }

    /**
     * 根据ID获取交易信息
     *
     * @param id
     * @return
     * @throws DBException
     */
    public TPvTuiHuiNotify findById(String id) throws DBException {
        String sql = "SELECT * FROM T_PV_TUI_HUI_NOTIFY WHERE ID=?";
        return DB.get(sql, new Object[]{id}, TPvTuiHuiNotify.class);
    }

    /**
     * 根据流水号获取交易信息
     *
     * @param txnNo
     * @return
     * @throws DBException
     */
    public TPvTuiHuiNotify findByTxnNo(String txnNo) throws DBException {
        String sql = "SELECT * FROM T_PV_TUI_HUI_NOTIFY WHERE TXN_NO=?";
        return DB.get(sql, new Object[]{txnNo}, TPvTuiHuiNotify.class);
    }
}
